export function arrClassify(arr) {
  function arrayToTree(pid) {
    var temp = []
    for (var index in arr) {
      if (arr[index].pid === pid) {
        temp.push(
          Object.assign(arr[index], {children: arrayToTree(arr[index].id)})
        )
      }
    }
    return arrOrder(temp)
  }
  return arrOrder(arrayToTree(0))
}

function arrOrder(arr) {
  return arr.sort(sortBy)
}

function sortBy(a, b) {
  return a.orderNum - b.orderNum
}
